package com.yurun.controller.admin;

import com.yurun.entity.User;
import com.yurun.model.vo.Result;
import com.yurun.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
public class UserAdminController {
    @Autowired
    UserService userService;
    /**
     * @Description: 添加用户
     * @Param: user
     * @return: com.yurun.model.vo.Result
     * @Author: JimmyYao
     * @Date: 2022/2/9
     */
    @PostMapping("/user")
    public Result addUser(@RequestBody User user){
        userService.addUser(user);
        return Result.ok("添加用户成功");
    }
    /**
     * @Description: 通过ID-删除用户
     * @Param: id
     * @return: com.yurun.model.vo.Result
     * @Author: JimmyYao
     * @Date: 2022/2/9
     */
    @DeleteMapping("/user/id")
    public Result deleteUserById(@RequestParam Long id){
        userService.deleteUserById(id);
        return Result.ok("删除用户成功");
    }
    /**
     * @Description: 通过ID-更新用户头像
     * @Param: id
	 * @Param  avator
     * @return: com.yurun.model.vo.Result
     * @Author: JimmyYao
     * @Date: 2022/2/9
     */
    @PutMapping("/useravator/id")
    public Result updateUserAvatorById(@RequestParam Long id,
                                     @RequestParam String avator){
        userService.updateUserAvatorById(id, avator);
        return Result.ok("更新用户头像成功");
    }
    /**
     * @Description: 获取用户列表
     * @Param:
     * @return: com.yurun.model.vo.Result
     * @Author: JimmyYao
     * @Date: 2022/2/9
     */
    @GetMapping("/userlist")
    public Result getUserList(){
        List<User> object=userService.getUserList();
        return Result.ok("获取用户列表成功",object);
    }
}
